<template>
    <el-form :rules="rules" :ref="formName" :model="form" class="dept-form" label-width="100px">
        <el-row>
            <el-col :span="24">
                <el-form-item label="部门名称" prop="name">
                    <el-input v-model="form.name" placeholder="请填写部门名称"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="24" >
                <el-form-item label="上级部门" prop="parentName">
                    <el-input disabled v-model="form.parentName"></el-input>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item label="排序" prop="orderNum">
                    <el-input-number v-model="form.orderNum" controls-position="right" :min="form.orderNum" :max="100"></el-input-number>
                </el-form-item>
            </el-col>
        </el-row>
    </el-form>
</template>

<script>
    export default {
        props: {
            form: {
                type: Object,
                default: {
                    name: null,
                    parentId: null,
                    parentName: null,
                    orderNum: 0
                }
            }
        },
        data() {
            return {
                formName: 'deptForm',
                rules: {
                    name: [
                        { required: true, message: '请填写部门名称', trigger: 'blur' },
                        { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            validate(func = (valid) => {}) {
                this.$refs[this.formName].validate(func);
            },
            resetFields() {
                this.$refs[this.formName].resetFields();
            }
        }
    };
</script>
